% Figure 2
 axoptions={'scaled ticks = false',...
           'y tick label style={/pgf/number format/.cd, fixed, fixed zerofill,precision=0, set thousands separator={}}',...
           'x tick label style={/pgf/number format/.cd,fixed, fixed zerofill, precision=0, set thousands separator={}}',...
           'z tick label style={/pgf/number format/.cd, fixed, fixed zerofill, precision=2, set thousands separator={}}',...
           'legend style={font=\normalsize}'}; %\scriptsize
 
if ~isfile('../data/DataforMatlab/Fig2iterdata.mat')
    run("sub_Figure2_pre1.m")
end 

load ../data/DataforMatlab/Fig2iterdata.mat
freq = (tt./40);
figure('name','Figure 2 (a)','NumberTitle','off')
[X,Y] = meshgrid(freq,nn);
s = surf(Y,X,error_mat(:,:,1)','FaceAlpha',0.5);
s.EdgeColor = 'none';
s.FaceColor = 'interp';
set(gca,'YScale','log','YMinorGrid','off')
colormap winter 
xticks([50 100 200])
yticklabels({'10^{-1}','10^0','10^1'})
view(-230,30)
xlabel('Sample Size')
ylabel('Frequency')
zlabel('Error Size')
zlim([0,0.08])
lims = clim;
grid on
xh = get(gca,'XLabel'); % Handle of the x label
set(xh, 'Units', 'Normalized')
pos = get(xh, 'Position');
set(xh, 'Position',pos.*[1,-.3,1],'Rotation',30)
yh = get(gca,'YLabel'); % Handle of the y label
set(yh, 'Units', 'Normalized')
pos = get(yh, 'Position');
set(yh, 'Position',pos.*[1,-.3,1],'Rotation',-18)
%matlab2tikz('../fig/Error_iter_3d.tex','extraAxisOptions',axoptions,'Location','northeast')%,'extraAxisOptions',axoptions);

%%
if ~isfile('../data/DataforMatlab/Fig2iterdata_FP.mat')
    run("sub_Figure2_pre2.m") 
end 
 axoptions={'scaled ticks = false',...
           'y tick label style={/pgf/number format/.cd, fixed, fixed zerofill,precision=0, set thousands separator={}}',...
           'x tick label style={/pgf/number format/.cd,fixed, fixed zerofill, precision=0, set thousands separator={}}',...
           'z tick label style={/pgf/number format/.cd, fixed, fixed zerofill, precision=2, set thousands separator={}}',...
           'legend style={font=\normalsize}'}; %\scriptsize

figure('name','Figure 2 (b)','NumberTitle','off')
load ../data/DataforMatlab/Fig2iterdata_FP.mat
freq = (tt./40);
[X,Y] = meshgrid(freq,nn);
s = surf(Y,X,error_mat(:,:,1)','FaceAlpha',0.5);
s.EdgeColor = 'none';
s.FaceColor = 'interp';
set(gca,'YScale','log','YMinorGrid','off')
colormap winter
xticks([50 100 200])
yticks([0.1 1 10])
yticklabels({'10^{-1}','10^0','10^1'})
view(-230,30)
zlim([0,0.08])
clim(lims)
xlabel('Sample Size')
ylabel('Frequency')
zlabel('Error Size')
grid on
xh = get(gca,'XLabel'); % Handle of the x label
set(xh, 'Units', 'Normalized')
pos = get(xh, 'Position');
set(xh, 'Position',pos.*[1,1.5,1],'Rotation',30)
yh = get(gca,'YLabel'); % Handle of the y label
set(yh, 'Units', 'Normalized')
pos = get(yh, 'Position');
set(yh, 'Position',pos.*[1,-.3,1],'Rotation',-18)
%matlab2tikz('../fig/Error_fixed_3d.tex','extraAxisOptions',axoptions,'Location','northeast')%,'extraAxisOptions',axoptions);